from django.db import models

# Create your models here.
from area.models import Address
from base_model import BaseModel
from user.models import User


class Order(BaseModel):
    PAY_WAY = (
        ('0', '货到付款'),
        ('1', '支付宝付款'),
        ('2', '微信付款')
    )
    PAY_STATUS = (
        ('0', '待支付'),
        ('1', '待发货'),
        ('2', '待收货'),
        ('3', '待评价'),
        ('4', '已完成'),
        ('5', '已取消')
    )
    order_sn = models.CharField(max_length=64, db_index=True, verbose_name='订单号')
    user = models.ForeignKey(User, on_delete=models.CASCADE, related_name='order', verbose_name='用户')
    account = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='总金额')
    freight = models.DecimalField(max_digits=10, null=True, blank=True, decimal_places=2, verbose_name='运费')
    pay_method = models.CharField(choices=PAY_WAY, default='0', max_length=2, verbose_name='支付方式')
    status = models.CharField(max_length=2, choices=PAY_STATUS, default='0', verbose_name='支付状态')
    total = models.IntegerField(default=0, verbose_name='总数')
    address = models.ForeignKey(Address, on_delete=models.CASCADE, related_name='order', verbose_name='地址')

    class Meta:
        db_table = 'order'
        verbose_name = '订单表'
        verbose_name_plural = verbose_name


class Payment(BaseModel):
    payment_sn = models.CharField(max_length=64, db_index=True, verbose_name='支付编号')
    order = models.ForeignKey(Order, on_delete=models.CASCADE, null=True, blank=True, related_name='payment')

    class Meta:
        db_table = 'payment'
        verbose_name = '支付表'
        verbose_name_plural = verbose_name
